<?php

namespace app\admin\model;

use think\Model;


class YjyHouse extends Model
{

    

    //数据库
    protected $connection = 'database';
    // 表名
    protected $name = 'yjy_house';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'is_recommend_text',
        'status_text',
        'house_status_text'
    ];
    

    
    public function getIsRecommendList()
    {
        return ['0' => __('Is_recommend 0'), '1' => __('Is_recommend 1')];
    }

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1')];
    }

    public function getHouseStatusList()
    {
        return ['1' => __('House_status 1'), '2' => __('House_status 2')];
    }


    public function getIsRecommendTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_recommend']) ? $data['is_recommend'] : '');
        $list = $this->getIsRecommendList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getHouseStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['house_status']) ? $data['house_status'] : '');
        $list = $this->getHouseStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function yjyhousetags()
    {
        return $this->belongsTo('YjyHouseTags', 'tags_ids', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function yjyhousearea()
    {
        return $this->belongsTo('YjyHouseArea', 'area_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function yjyhouseconfig()
    {
        return $this->belongsTo('YjyHouseConfig', 'config_ids', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function yjyhouselandlord()
    {
        return $this->belongsTo('YjyHouseLandlord', 'landlord_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
